package com.bw.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.service.KcService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@Slf4j
@RestController
public class KcController {

    @Autowired
    private KcService kcService;

    @RequestMapping("/s1")
    public JSONObject select1(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONObject data = new JSONObject();
        result.put("data",data);

        JSONArray categories = new JSONArray();
        JSONArray series = new JSONArray();

        data.put("categories",categories);
        data.put("series",series);

        List<Map<String ,Object>> maps=kcService.select1();

        JSONObject series_1 = new JSONObject();
        series_1.put("name","sb");
        series.add(series_1);

        JSONArray series_data = new JSONArray();
        series_1.put("data",series_data);

        for (Map<String, Object> map : maps) {
            categories.add(map.get("name"));
            series_data.add(map.get("cta"));
        }


        return  result;
    }
    @RequestMapping("/s2")
    public JSONObject select2() {
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONObject data = new JSONObject();
        result.put("data",data);
        JSONArray mapData = new JSONArray();
        data.put("mapData",mapData);
        data.put("valueName","运单数量");
        data.put("sizeValueName","运单金额");
        List<Map<String ,Object>> maps=kcService.select2();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("name",map.get("name"));
            row.put("value",map.get("cta"));
            row.put("sizeValue",map.get("ctb"));
            mapData.add(row);
        }
        return result;
    }

    @RequestMapping("/s3")
    public JSONObject select3() {
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONObject data = new JSONObject();
        result.put("data",data);
        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();
        data.put("columns",columns);
        data.put("rows",rows);
        JSONObject col1 = new JSONObject();
        col1.put("name","序号");
        col1.put("id","id");

        columns.add(col1);

        JSONObject col2 = new JSONObject();
        col2.put("name","序号");
        col2.put("id","name");

        columns.add(col2);

        JSONObject col3 = new JSONObject();
        col3.put("name","序号");
        col3.put("id","cta");

        columns.add(col3);

        JSONObject col4 = new JSONObject();
        col4.put("name","序号");
        col4.put("id","ctb");

        columns.add(col4);

        JSONObject col5 = new JSONObject();
        col5.put("name","序号");
        col5.put("id","ctc");

        columns.add(col5);

        List<Map<String ,Object>> maps=kcService.select3();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("id",map.get("id"));
            row.put("name",map.get("name"));
            row.put("cta",map.get("cta"));
            row.put("ctb",map.get("ctb"));
            row.put("ctc",map.get("ctc"));
            rows.add(row);
        }

        return result;
    }

    @RequestMapping("/s4")
    public JSONObject select4() {
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONObject data = new JSONObject();
        result.put("data",data);
        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();
        data.put("columns",columns);
        data.put("rows",rows);
        JSONObject col1 = new JSONObject();
        col1.put("name","序号");
        col1.put("id","id");

        columns.add(col1);

        JSONObject col2 = new JSONObject();
        col2.put("name","序号");
        col2.put("id","name");

        columns.add(col2);

        JSONObject col3 = new JSONObject();
        col3.put("name","序号");
        col3.put("id","cta");

        columns.add(col3);

        JSONObject col4 = new JSONObject();
        col4.put("name","序号");
        col4.put("id","ctb");

        columns.add(col4);

        JSONObject col5 = new JSONObject();
        col5.put("name","序号");
        col5.put("id","ctc");

        columns.add(col5);

        List<Map<String ,Object>> maps=kcService.select4();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("id",map.get("id"));
            row.put("name",map.get("name"));
            row.put("cta",map.get("cta"));
            row.put("ctb",map.get("ctb"));
            row.put("ctc",map.get("ctc"));
            rows.add(row);
        }

        return result;
    }
    @RequestMapping("/s5")
    public JSONObject select5(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("mag","");
        JSONObject data = new JSONObject();
        result.put("data",data);

        JSONArray categories = new JSONArray();
        JSONArray series = new JSONArray();
        data.put("categories",categories);
        data.put("series",series);

        List<Map<String ,Object>> maps=kcService.select5();
        JSONObject series_1 = new JSONObject();
        series_1.put("name","name");
        series.add(series_1);
        JSONArray series_data = new JSONArray();
        series_1.put("data",series_data);

        for (Map<String, Object> map : maps) {
            categories.add(map.get("name"));
            series_data.add(map.get("cta"));
        }
        return  result;
    }
}
